package one.stand.controller;

import com.jmp.autocofiguration.web.interceptor.SecurityAuthCheck;
import com.jmp.feign.CardFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.jmp.api.dto.CardWxcodeUpdateRequest;
import one.stand.model.ResultModel;
import one.stand.util.RequestContext;
import one.stand.util.RequestContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "名片")
@RestController
@RequestMapping("crmApi/card")
public class CardController {

    @Autowired
    private CardFeign cardFeign;

    @ApiOperation(value = "更新名片-微信二维码")
    @PostMapping("/wxcode/update")
    @SecurityAuthCheck(company = true, card = true)
    public ResultModel wxcodeUpdate(@RequestAttribute CardWxcodeUpdateRequest request) {
        final RequestContext.User user = RequestContextHolder.getRequestContext().getUser();

        com.jmp.base.dto.CardWxcodeUpdateRequest updateRequest = com.jmp.base.dto.CardWxcodeUpdateRequest.builder()
                .cardId(user.getCardId())
                .wxCode(request.getWxCode())
                .build();
        cardFeign.wxcodeUpdate(updateRequest);

        return ResultModel.success();
    }
}
